<?php

class Response
{
    /**
     * content
     * @var string
     */
    protected $_content = '';

    /**
     * @param string $content
     * @return Response
     */
    public function setContent($content)
    {
        $this -> _content = $content;
        return $this;
    }

    /**
     * get content
     * @return string
     */
    public function getContent()
    {
        return $this -> _content;
    }

    /**
     * @param string $content
     * @return Response
     */
    public function appendContent($content)
    {
        $this -> _content .= $content;
        return $this;
    }

    /**
     * @param string $content
     * @return Response
     */
    public function prependContent($content)
    {
        $this -> _content = $content . $this -> _content;
        return $this;
    }
    
    /**
     * close & write session then redirect by new location.
     * @param string $url
     * @param array $params
     * @return void
     * 
     */
    public function redirect($url = '', $params = null)
    {
        if (empty($url) or strpos($url, 'http') !== 0)
        {
            $url = Nuo::getUrl($url, $params);
        }
		
        session_write_close();

        if (headers_sent())
        {
            throw new Exception("header sent.");
        }

        header('location:' . $url);
    }

}
